package com.ruoyi.web.controller.topic;


import com.ruoyi.system.domain.Dynamic;
import com.ruoyi.system.domain.vo.Result;
import com.ruoyi.system.service.DynamicService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "动态评论模块")
@RestController
@RequestMapping("/api")
public class DynamicController extends BaseController  {


    @Autowired
    private DynamicService dynamicService;

    @ApiOperation("新增评论")
    @PostMapping("/dynamics")
    public Result<?> addDynamic(@RequestBody Dynamic dynamic){
        return Result.success(dynamicService.saveDynamic(dynamic));
    }

    @ApiOperation("删除评论")
    @GetMapping("/dynamics/{id}/delete")
    public Result<?> deleteComment(Dynamic dynamic,@PathVariable("id") Long id){
        dynamicService.deleteDynamic(dynamic,id);
        return Result.success();
    }

    @ApiOperation("通过DynamicId查询评论列表")
    @GetMapping("/dynamics/{dynamicId}")
    public Result<?> dynamicList(@PathVariable("dynamicId") Long dynamicId){
        List<Dynamic> dynamics =
                dynamicService.listDynamicByDynamicId(dynamicId);
        return Result.success(dynamics);
    }

    @ApiOperation("通过userId查询评论列表")
    @GetMapping("/dynamics/userId/{userId}")
    public Result<?> dynamics(@PathVariable("userId") Long userId){
        List<Dynamic> dynamics =
                dynamicService.getDynamicByUserId(userId);
        return Result.success(dynamics);
    }

}
